#ifndef __FLASH_MX35LFXX_DRV_H
#define __FLASH_MX35LFXX_DRV_H

#include <zephyr/types.h>

#define FLASH_ID 0xC220
#define FLASH_SIZE 0x10000000 /* 256 MB */

/* Flash Related Parameter Define */
#define BLOCK_SIZE 0x20000       /* 128K Block size */
#define PAGE_SIZE 0x800          /* 2K Byte Page size */
#define PAGE_SIZE_WITH_OOB 0x840 /* (2048 + 64) Bytes*/
#define BLOCK_NUM (FLASH_SIZE / BLOCK_SIZE)

/* system flags */
#define PASS 0
#define FAIL 1
#define BUSY 0
#define READY 1
#define PROTECTED 0
#define UNPROTECTED 1

/* bool Definition */
#define TRUE 1
#define FALSE 0
#define BYTE_LEN 8
#define IO_MASK 0x80
#define HALF_WORD_MASK 0x0000ffff
#define TIMEOUT 0
#define TIMENOTOUT 1

#define BYTE_MASK 0xFF

/**
 * Flash control register mask define
 * status register
 * status register [7:0]
 */
#define SR0_OIP 0x01
#define SR1_WEL 0x02
#define SR2_ERASE_FAILED 0x04
#define SR2_PROGRAM_FAILED 0x08

#define FLASH_QE_MASK 0x01

/* ID comands */
#define FLASH_CMD_RDID 0x9F                  /* RDID (Read Identification) */
#define FLASH_CMD_GET_FEATURE 0x0F           /* Get features */
#define FLASH_CMD_SET_FEATURE 0x1F           /* Set features */
#define FLASH_CMD_READ 0x13                  /* Array Read */
#define FLASH_CMD_READ_CACHE 0x03            /* Read From Cache */
#define FLASH_CMD_READ_CACHE2 0x3B           /* Read From Cache*2 */
#define FLASH_CMD_READ_CACHE4 0x6B           /* Read From Cache*4 */
#define FLASH_CMD_READ_CACHE_SEQUENTIAL 0x31 /* Read From Cache Sequential */
#define FLASH_CMD_READ_CACHE_END 0x3F        /* Read From Cache End */
#define FLASH_CMD_WREN 0x06                  /* Write Enable */
#define FLASH_CMD_WRDI 0x04                  /* Write Disable */
#define FLASH_CMD_PP_LOAD 0x02               /* Page Program Load */
#define FLASH_CMD_PP_RAND_LOAD 0x84          /* Page Program Random Input */
#define FLASH_CMD_4PP_LOAD 0x32              /* Quad IO Page Program Load */
#define FLASH_CMD_4PP_RAND_LOAD 0x34         /* Quad IO Page Program Random Input */
#define FLASH_CMD_PROGRAM_EXEC 0x10          /* Program Execute */
#define FLASH_CMD_BE 0xD8                    /* BLock Erase */
#define FLASH_CMD_DUMMY_DATA 0xFF

enum {
    FEATURE_CONFIG = 0xB0,
    FEATURE_STATUS = 0xC0,
    FEATURE_BLOCK_PROTECTION = 0xA0,
};

typedef enum {
    FLASH_SUCCESS,
    FLASH_BUSY,
    FLASH_OPERATION_TIMEOUT,
    FLASH_PROGRAM_FAILED,
    FLASH_ERASE_FAILED,
    FLASH_READ_ID_FAILED,
    FLASH_CMD_INVALID,
    FLASH_DATA_INVALID,
    FLASH_ADDR_INVALID,
    FLASH_QUAD_NOT_ENABLE
} ret_msg_t;

#endif /* __FLASH_MX35LFXX_DRV_H */
